catan.board = {	
	drawBoard: function(board_id) {
		var c2 = $('canvas#' + board_id)[0].getContext('2d');
		var points = [
		    [10,0],
		    [20,10],
		    [20,20],
		    [10,30],
		    [0,20],
		    [0,10]
		];
		
		c2.beginPath();
		var p = points[points.length - 1];
		c2.moveTo(p[0], p[1]);
		for (var i = 0; i < points.length; i++) {
			p = points[i];
			c2.lineTo(p[0], p[1]);
		}
		c2.closePath();
		c2.stroke();
	}

	getNewMap: function() {
		var tiles = catan.tiles;
		var types = tiles.types();
		var counts = tiles.counts();
		
		var total_tiles = 0;
		var non_desert = 0;
		
		for (var i = 0; i < types.length; i++) {
			var type = types[i];
			total_tiles += counts[type];
			if (counts[type] == 0) {
				types.splice(i, 1);
				i--;
			}
		}
		non_desert = total_tiles - counts.desert;
		
		var cur_tile = null;
		var next_pos = 0;
		var center = null;
		var pending = [];
		while (total_tiles > 0) {			
			
			var new_tile = {neighbours: {}};			
			var r = Math.floor(Math.random() * total_tiles);
			var type = types[r];
			new_tile.type = type;			
			counts[type]--;
			if (counts[type] == 0) {
				types.splice(r, 1);
			}
			total_tiles--;
			if (type != 'desert') non_desert--;
			
			if (!cur_tile) {
				cur_tile = new_tile;
				center = new_tile;
				continue;
			}			
			
			while (cur_tile.neighbours[next_pos]) {
				next_pos++;
				if (next_pos == 6) {
					break;
				}
			}
			if (next_pos == 6) {
				
			}
		}		
	}
};